# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Michael Schubert <mschu.dev at gmail>

pkgname=symengine
pkgver=0.10.1
pkgrel=1
pkgdesc='Fast symbolic manipulation library, written in C++'
url='http://sympy.org/'
arch=(loong64 x86_64)
license=(MIT)
depends=(llvm-libs arb libmpc gmp-ecm primesieve gperftools)
makedepends=(cmake boost llvm cereal)
source=(https://github.com/symengine/symengine/releases/download/v$pkgver/$pkgname-$pkgver.tar.gz
        llvm-shared.patch)
sha256sums=('9c007c99e9633f5549a55fa7a66ebcbcf9e04092eb55f7bb781c22b9cf0570c4'
            'ef05a806139b35e0336f00cb6960ef6cf483f11b0041e436a99ab1f46bdcb11c')

prepare() {
  patch -d $pkgname-$pkgver -p1 < llvm-shared.patch # Use shared LLVM (Gentoo)
}

build() {
  cmake -B build -S $pkgname-$pkgver \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED_LIBS=ON \
    -DWITH_TCMALLOC=ON \
    -DWITH_PTHREAD=ON \
    -DWITH_SYMENGINE_THREAD_SAFE=ON \
    -DWITH_ARB=ON \
    -DWITH_ECM=ON \
    -DWITH_LLVM=ON \
    -DWITH_MPFR=ON \
    -DWITH_MPC=ON \
    -DWITH_PRIMESIEVE=ON \
    -DWITH_BOOST=ON \
    -DWITH_COTIRE=OFF \
    -DWITH_SYSTEM_CEREAL=ON
  cmake --build build
}

check() {
  cmake --build build --target test
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -Dm644 $pkgname-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
}
